package cn.study.jmm;

/**
 * @Author     ：跟大佳一起学
 * @Description：可见性
 */
public class VolatileTest {
    private static boolean flag = true;
    public static void main(String[] args) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    if (flag){
                        System.out.println("turn on");
                        flag = false;
                    }
                }
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    if (!flag){
                        System.out.println("turn off");
                        flag = true;
                    }
                }
            }
        }).start();
    }
}